package LifeTest;

import java.util.Iterator;

public class Solution {
	
	public static int countBattleships(char[][] board) {
		    int count = 0;
			int m = board.length,n = board[0].length;
			int[] flag = new int[n];
			for (int i = 0; i < m; i++) {
				for (int j = 0; j < n; j++) {
	                if(board[i][j] == '.');
	                else if(flag[j] != 'X' && (j ==0 || board[i][j - 1] != 'X'))
						count++;
					flag[j] = board[i][j];
				}
			}
			return count;
	    }
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		char[][] a = {{'.','X','.','.','X'},{'.','X','.','.','X'},{'.','.','.','.','X'},{'X','.','X','X','.'},{'X','.','.','.','X'}};
		System.out.println(countBattleships(a));
	}
}
